package com.darren.befriend.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.darren.befriend.R;
import com.darren.befriend.models.HobbyModel;
import com.darren.befriend.utilities.Utilities;

public class InterestAdapter extends BaseAdapter {
	
	private Context mContext;
	private ArrayList<HobbyModel> mInterestArr;
	
	public InterestAdapter(Context c, ArrayList<HobbyModel> interestArr) {
		mContext = c;		
		mInterestArr = interestArr;
	}
	@Override
	public int getCount() {
		return mInterestArr.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public int getItemViewType(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View item;
		InterestHolder holder = null;
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);		
        if (convertView == null) {
        	holder = new InterestHolder();
        	item = inflater.inflate(R.layout.layout_interest_item, null);
        	
        	holder.interestTxt = (TextView) item.findViewById(R.id.item_text);
        	Utilities.setFontType(mContext, holder.interestTxt);
        	holder.interestImg = (ImageView) item.findViewById(R.id.item_image);        	
        	holder.selectedtImg = (ImageView) item.findViewById(R.id.selected_icon);        	
        	item.setTag(holder);
        } else {
        	item = (View) convertView;
        	holder = (InterestHolder) item.getTag();
        }        
        holder.interestTxt.setText(mInterestArr.get(position).interestText);
        holder.interestImg.setImageResource(mInterestArr.get(position).interestIconRes);
        if (mInterestArr.get(position).isSelected == true && mInterestArr.get(position).isEmpty == false) {
        	holder.selectedtImg.setVisibility(View.VISIBLE);
        } else {
        	holder.selectedtImg.setVisibility(View.INVISIBLE);
        }
        return item;
	}
	
	static class InterestHolder {
		ImageView interestImg;
		ImageView selectedtImg;
		TextView interestTxt;
	}

}
